import axios from "axios";

const requests=axios.create({
    //设置超时时间，单位毫秒
    timeout:5000
})
requests.interceptors.response.use((response)=>{
    let {code}=response.data;
    if(code==200){
        return response.data;
    }
    if(code==302&&response.data.loginStatus==false){
        alert("请先登录");
        window.location.replace(`http://${window.location.host}/`)
    }
    return response.data;
},error=>{
    return Promise.reject(new Error(error));
})

export default requests;